home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / NeoIntroPP3.0 folder / PowerPlant / NeoBench / Source / CNeoBenchApp.cp < prev    next >
Encoding:
Text File  |  1994-09-04  |  5.1 KB  |  230 lines  |  [TEXT/MMCC]

  1. /*****
  2.  * CNeoBenchApp.cp
  3.  *
  4.  *    Application methods for a typical application.
  5.  *
  6.  *  Copyright © 1992-1993 NeoLogic Systems.  All rights reserved.
  7.  *
  8.  *****/
  9.  
  10. #include "NeoTypes.h"
  11. #include <stdlib.h>
  12. #include <Timer.h>
  13. #include "UDesktop.h"
  14. #include "UMemoryMgr.h"
  15. #include "UPowerTools.h"
  16. #include "LGrowZone.h"
  17. #include "LList.h"
  18. #include "CNeoWindow.h"
  19. #include "CNeoBenchApp.h"
  20. #include "CNeoBenchDoc.h"
  21. #include CNeoDatabaseNativeH
  22. #include "CFiller.h"
  23. #include CNeoMetaClassH
  24. #ifdef qNeoThreads
  25. #include <LThread.h>
  26. #include CNeoThreadNativeH
  27. #endif
  28.  
  29. #include "CIDIndex.h"
  30.  
  31. extern    OSType    gSignature;
  32.  
  33. int main(void)
  34. {
  35.     CNeoBenchApp *    app;
  36.  
  37.     InitializeHeap(4);
  38.     InitializeToolbox();
  39.     new LGrowZone(20000);
  40.  
  41.     app = new CNeoBenchApp();
  42.     app->Run();
  43.     delete app;
  44.  
  45.     return 0;
  46. }
  47.  
  48. /***
  49.  * CNeoBenchApp
  50.  *
  51.  *    Initialize the application. Your initialization method should
  52.  *    at least call the inherited method. If your application class
  53.  *    defines its own instance variables or global variables, this
  54.  *    is a good place to initialize them.
  55.  *
  56.  ***/
  57. CNeoBenchApp::CNeoBenchApp(void)
  58.     : CNeoAppRoot(kNeoBenchSig, kNeoBenchFileType)
  59. {
  60.     long        index;
  61.     long        delay    = 0;
  62.     TMTask        timer;
  63.  
  64. #ifdef qNeoThreads
  65.     new CBenchThread(nil, kNeoCoopThread, nil, kNeoDefaultStackSize, CBenchThread::threadOption_Main);
  66. #endif
  67.  
  68.     FFileType = kNeoBenchFileType;
  69.  
  70.     // Add CFiller class to the metaclass table
  71.     new CNeoMetaClass(kFillerID, kNeoPersistID, kFillerName, CFiller::New);
  72. //    meta->setKey(kNeoSecondaryIndex, kIDIndexID);
  73.  
  74. //    // Add CIDINdex class to the metaclass table
  75. //    meta = new CNeoMetaClass(kIDIndexID, kNeoNullClassID, "\pCIDIndex", CIDIndex::New, CIDIndex::KeyManager);
  76.  
  77.     // Bound the default size of the NeoAccess object cache to be 3/4 of free memory
  78.     CNeoPersist::FCacheSize = ((FreeMem() / 4) * 3);
  79. //    CNeoPersist::FCacheSize = (FreeMem() / 4);
  80.  
  81.     // Just to make sure that we get more random results.
  82.     srand((unsigned int)clock());
  83.  
  84.     // measure Time Manager overhead
  85.     timer.tmAddr        = NULL;
  86.     timer.tmCount        = 0;
  87.     timer.tmWakeUp        = 0;
  88.     timer.tmReserved    = 0;
  89.     
  90.     for (index = 0; index < 100; index++) {
  91.         InsTime((QElemPtr)&timer);
  92.         PrimeTime((QElemPtr)&timer, k30MicroMinutes);
  93.         RmvTime((QElemPtr)&timer);
  94.         
  95.         if (timer.tmCount > 0)
  96.             // milliseconds
  97.             delay += -(k30MicroMinutes + timer.tmCount * 1000);
  98.         else
  99.             // negated microseconds
  100.             delay += -(k30MicroMinutes - timer.tmCount);
  101.     }
  102.     
  103.     // compute average overhead
  104.     gLoopOverhead = delay / 100;
  105. }
  106.  
  107. CNeoBenchApp::~CNeoBenchApp(void)
  108. {
  109. #ifdef qNeoThreads
  110. //    LThread::ExitThreads();
  111. #endif
  112. }
  113.  
  114. /***
  115.  * createDocument
  116.  *
  117.  *    The user chose New from the File menu.
  118.  *    In this method, you need to create a document and send it
  119.  *    a newFile message.
  120.  *
  121.  ***/
  122. CNeoDoc    *CNeoBenchApp::createDocument(void)
  123. {
  124.     CNeoBenchDoc *    document = nil;
  125.  
  126.     NEOTRY {
  127.         /**
  128.          **    Create your document.
  129.          **
  130.          **/
  131.         document = new CNeoBenchDoc(FALSE, TRUE, FALSE);
  132.         NeoFailNil(document);
  133.         document->SetSuperCommander(this);
  134.  
  135.         /**
  136.          **    Send the document a NewFile() message.
  137.          **    The document will open a window, and
  138.          **    set up the heart of the application.
  139.          **
  140.          **/
  141.         document->newDatabase();
  142.     }
  143.     NEOCATCH {
  144.         /*
  145.          * This exception handler gets executed if a failure occurred
  146.          * anywhere within the scope of the TRY block above. Since
  147.          * this indicates that a new doc could not be created, we
  148.          * check if an object had been allocated and if it has, send
  149.          * it a unrefer message. The exception will propagate up to
  150.          * CSwitchboard's exception handler, which handles displaying
  151.          * an error alert.
  152.          */
  153.  
  154.         if (document) {
  155.             delete document;
  156.             document = nil;
  157.         }
  158.     }
  159.     NEOENDTRY;
  160.  
  161.     return document;
  162. }
  163.  
  164. /***
  165.  * OpenDocument
  166.  *
  167.  *    The user chose Open… from the File menu.
  168.  *    In this method you need to create a document
  169.  *    and send it an OpenFile() message.
  170.  *
  171.  *    The macSFReply is a good SFReply record that contains
  172.  *    the name and vRefNum of the file the user chose to
  173.  *    open.
  174.  *
  175.  ***/
  176.  
  177. void CNeoBenchApp::OpenDocument(FSSpec *aSpec)
  178. {
  179.     Boolean            remote;
  180.     CNeoBenchDoc *    document    = nil;
  181.  
  182. #ifdef qNeoShare
  183.     remote = fOpeningRemote;
  184. #else
  185.     remote = FALSE;
  186. #endif
  187.  
  188.     VOLATILE(document);
  189.  
  190.     NEOTRY {
  191.         // Our parent will check to see if this is a document we have already opened.
  192.         // If we find the file already open by the app, then fDocument will refer to it.
  193.         // If the file is opened but not by this app, then the parent will signal a failure.
  194.         inherited::OpenDocument(aSpec);
  195.         if (fDocument)
  196.             return;
  197.  
  198.         /**
  199.          **    Create your document.
  200.          **
  201.          **/
  202.         document = new CNeoBenchDoc(TRUE, FALSE, remote);
  203.         NeoFailNil(document);
  204.         document->SetSuperCommander(this);
  205.  
  206.         /**
  207.          **    Send the document an OpenFile() message.
  208.          **    The document will open a window, open
  209.          **    the file specified in the macSFReply record,
  210.          **    and display it in its window.
  211.          **
  212.          **/
  213.         document->openFile(aSpec);
  214.     }
  215.     NEOCATCH {
  216.         /*
  217.          * This exception handler gets executed if a failure occurred
  218.          * anywhere within the scope of the TRY block above. Since
  219.          * this indicates that the document could not be opened, we
  220.          * send it a unrefer message. The exception will propagate up to
  221.          * CSwitchboard's exception handler, which handles displaying
  222.          * an error alert.
  223.          */
  224.         if (document)
  225.             delete document;
  226.     }
  227.     NEOENDTRY;
  228. }
  229.  
  230.